using UnityEngine;
using Yoozoo.Libs;

namespace Gameplay.PVE.TurnBase
{
    public class ChangePropertyElement : ElementBase
    {
        private float value;

        public override void Execute()
        {
            base.Execute();
            int attributeId = GetValue("AttributeID");
            int calculateType = GetValue("CalculateType");
            endRound = GetValue("LastRound") + TurnBaseManager.Instance.GetRound();
            if (attributeId == 1)
            {
                if (calculateType == 3)
                {
                    value = target.Data.AttackValue * config.output / 10000f;
                    target.Data.AttackValue += value;
                }
            }
            else if (attributeId == 2)
            {
                if (calculateType == 3)
                {
                    value = target.Data.DefenceValue * config.output / 10000f;
                    target.Data.DefenceValue += value;
                }
            }
            PveFlyTextManager.Instance.ShowFlyText(config.flyText + value,target.Data.position + new Vector3(0,0.2f,0));
        }

        public override void Free()
        {
            int attributeId = GetValue("AttributeID");
            int calculateType = GetValue("CalculateType");
            if (attributeId == 1)
            {
                if (calculateType == 3)
                {
                    target.Data.AttackValue -= value;
                }
            }
            else if (attributeId == 2)
            {
                if (calculateType == 3)
                {
                    target.Data.DefenceValue -= value;
                }
            }
            base.Free();
        }
    }
}